package com.yiqi.zhiyuan.common.romgim;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.text.TextUtils;

import java.util.LinkedHashMap;

import io.rong.common.RLog;
import io.rong.imlib.model.UserInfo;

public class SealUserInfoManager {

    private final static String TAG = "SealUserInfoManager";
    private static final int GET_TOKEN = 800;

    private HandlerThread mWorkThread;
    /**
     * 用户信息全部未同步
     */
    private static final int NONE = 0;//00000
    /**
     * 好友信息同步成功
     */
    private static final int FRIEND = 1;//00001
    /**
     * 群组信息同步成功
     */
    private static final int GROUPS = 2;//00010
    /**
     * 群成员信息部分同步成功,n个群组n次访问网络,存在部分同步的情况
     */
    private static final int PARTGROUPMEMBERS = 4;//00100
    /**
     * 群成员信息同步成功
     */
    private static final int GROUPMEMBERS = 8;//01000
    /**
     * 黑名单信息同步成功
     */
    private static final int BLACKLIST = 16;//10000
    /**
     * 用户信息全部同步成功
     */
    private static final int ALL = 27;//11011

    private static SealUserInfoManager sInstance;
    private final Context mContext;
    //    private final AsyncTaskManager mAsyncTaskManager;
//    private final SealAction action;
//    private DBManager mDBManager;
    private Handler mWorkHandler;
    static Handler mHandler;
    private SharedPreferences sp;

    private int mGetAllUserInfoState;
    private boolean doingGetAllUserInfo = false;

//    private FriendDao mFriendDao;

    private LinkedHashMap<String, UserInfo> mUserInfoCache;

    public static SealUserInfoManager getInstance() {
        return sInstance;
    }

    public SealUserInfoManager(Context context) {
        mContext = context;
        sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
//        action = new SealAction(mContext);
        mHandler = new Handler(Looper.getMainLooper());
        mWorkThread = new HandlerThread("sealUserInfoManager");
        mWorkThread.start();
        mWorkHandler = new Handler(mWorkThread.getLooper());
//        mGroupsList = null;
    }

    public static void init(Context context) {
        RLog.d(TAG, "SealUserInfoManager init");
        sInstance = new SealUserInfoManager(context);
    }

    /**
     * kit中提供用户信息的用户信息提供者
     * 1.读缓存
     * 2.读好友数据库
     * 3.读群组成员数据库
     * 4.网络获取
     */
    public void getUserInfo(final String userId) {
        if (TextUtils.isEmpty(userId)) {
            return;
        }

    }


}
